<template>
  <div class="home">
    <div class="nav">
      <li
        v-for="(item, index) in navData"
        :key="item.url"
        @click="handelClick(item, index)"
      >
        <transition
          tag="ul"
          v-bind:css="false"
          v-on:before-enter="beforeEnterGroup"
          v-on:leave="leaveGroup"
        >
          <img
            v-show="item.show"
            :src="
              item.isaction
                ? require('@/assets/' + item.actionUrl + '.png')
                : require('@/assets/' + item.url + '.png')
            "
            alt=""
          />
        </transition>
      </li>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: "Home",
  data() {
    return {
      navData: [
        {
          url: "home",
          actionUrl: "reHome",
          isaction: false,
          show: true,
        },
        {
          url: "elevator",
          actionUrl: "reElevator",
          isaction: false,
          show: true,
        },
        {
          url: "stop",
          actionUrl: "reStop",
          isaction: false,
          show: true,
        },
        {
          url: "energy",
          actionUrl: "reEnergy",
          isaction: false,
          show: true,
        },
        {
          url: "safe",
          actionUrl: "reSafe",
          isaction: false,
          show: true,
        },
        {
          url: "floor",
          actionUrl: "reFloor",
          isaction: false,
          show: true,
        },
      ],
    };
  },
  methods: {
    handelClick(item, index) {
      this.navData.forEach((element) => {
        if (item.url == element.url) {
          element.isaction = true;
        } else {
          element.isaction = false;
        }
      });
      item.show = false;
      setTimeout(() => {
        item.show = true;
      }, 300);
    },
  },
};
</script>
<style lang="scss" scoped>
.head {
  padding: 4px 6px;
  border: 1px solid #ddd;
}
.nav {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
}
.nav li {
  margin-bottom: 17px;
  list-style: none;
  height: 77px;
}
</style>
